package com.netty.demo.protobufexample;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.timeout.IdleStateEvent;

public class ProtobufServerHandler extends SimpleChannelInboundHandler<DataInfo.MyMessage> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, DataInfo.MyMessage msg) throws Exception {

        DataInfo.MyMessage.MessageType messageType = msg.getMessageType();
        if (messageType == DataInfo.MyMessage.MessageType.StudentType) {
            System.out.println(msg.getStudent().getName());
            System.out.println(msg.getStudent().getAddress());
            System.out.println(msg.getStudent().getId());
        }else  if (messageType == DataInfo.MyMessage.MessageType.CatType) {
            System.out.println(msg.getCat().getAge());
            System.out.println(msg.getCat().getName());
        }else  if (messageType == DataInfo.MyMessage.MessageType.DogType) {
            System.out.println(msg.getDog().getCity());
            System.out.println(msg.getDog().getName());
        }

    }
}
